package com.yuerlive.rainbow.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by xiaoyi on 2017/5/29.
 */

public class FormatUtil {
    public static String formatDealTotal(int count) {
        if (Math.abs(count) < 10000) {
            return String.valueOf(count);
        } else {
            return String.format("%.2f", Float.parseFloat(String.valueOf(count)) / 10000f) + "万";
        }
    }

    public static String formatTime(String timeStr, String source, String to) {
        SimpleDateFormat format = new SimpleDateFormat(source);
        try {
            Date date = format.parse(timeStr);
            format = new SimpleDateFormat(to);
            return format.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return timeStr;
    }

    public static String formatTime(long mills, String patter) {
        mills -= 8 * 60 * 60 * 1000;
        Date d = new Date(mills);
        SimpleDateFormat f = new SimpleDateFormat(patter);
        return f.format(d);
    }

    public static String formatCharmTotal(int count) {
        if (Math.abs(count) < 10000) {
            return String.valueOf(count);
        } else {
            return String.format("%.1f", Float.parseFloat(String.valueOf(count)) / 10000f) + "万";
        }
    }
}
